winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.75k stars 187 forks source link

Provide lifting support for custom computation utilities/classes. #6741

Open asterkin opened 1 week ago

asterkin commented 1 week ago

Use Case

I'm developing a custom utilities class and want it to be equally accessible in inflight and preflight modes. For example, pub enum DatetimeFormat { ISO, MMYYYY, YYYYMMDD_HHMM }

pub class Util { extern "./lib.js" static pub inflight toUtcString(date: std.Datetime): str; extern "./lib.js" static pub inflight plus(date: std.Datetime, offset: duration): std.Datetime; extern "./lib.js" static pub inflight minus(date: std.Datetime, offset: duration): std.Datetime; extern "./lib.js" static pub inflight format(date: std.Datetime, format: DatetimeFormat): str; extern "./lib.js" static pub inflight parse(date: str, format: DatetimeFormat): std.Datetime; extern "./lib.js" static pub inflight formatMMYYYY(date: std.Datetime): str; extern "./lib.js" static pub inflight parseMMYYYY(sd: str): std.Datetime; extern "./lib.js" static pub inflight formatYYYYMMDD_HHMM(date: std.Datetime): str; extern "./lib.js" static pub inflight parseYYYYMMDD_HHMM(sd: str): std.Datetime; } provides some additional computations for the std.Datetime class. All functions are defined as inflight which is their primary usage. However, I cannot use them in test setups since inflight functions cannot be called in the preflight context. This limitation leads to extra boilerplate code to be written.

Proposed Solution

  1. I did not find anywhere in the documentation the convention of public inflight functions available directly from the library/module. Just found it in the Wing libraries code.
  2. Make all inflight functions available in preflight (why not?), or provide a way to develop liftable classes, as it is done in the standard library. For example, I tried pub class Util impl std.ILiftable { ... } but it did not help.

Implementation Notes

The implementation already exists for Wing standard libraries. Just need to make it accessible for potential contributors.

Component

Compiler

Community Notes

Chriscbr commented 1 week ago

Related: https://github.com/winglang/wing/issues/435