winglang / wing

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

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

Open asterkin opened 5 months ago

asterkin commented 5 months 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 5 months ago

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

github-actions[bot] commented 2 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!