Skip to content

lazy_t cleanup part 2 #7484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 18, 2025
Merged

lazy_t cleanup part 2 #7484

merged 8 commits into from
May 18, 2025

Conversation

cknitt
Copy link
Member

@cknitt cknitt commented May 18, 2025

No description provided.

@cknitt
Copy link
Member Author

cknitt commented May 18, 2025

@cristianoc Also it causes this error (see CI failure):

FAILED: src/recursive_module.cmj

  We've found a bug for you!
  /home/runner/work/***/***/tests/tests/src/recursive_module.res:29:5-31:1

  27 │ module rec Inta: {
  28 │   let a: Lazy.t<int>
  29 │ } = {
  30 │   let a = Lazy.make(() => Lazy.get(Intb.a))
  31 │ }
  32 │ and Intb: {
  33 │   let a: Lazy.t<int>

  Cannot safely evaluate the definition
  of the recursively-defined module Inta

even when I make line 30

  30 │   let a: Lazy.t<int> = Lazy.make(() => Lazy.get(Intb.a))

instead.

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Half way there. A few comments on the hiccups encountered.

decl_abstr with
type_params = [tvar];
type_arity = 1;
type_variance = [Variance.covariant];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the difference: type lazy_t<+'a> with the +: covariant.

@@ -66,16 +66,6 @@ let init_shape modl =
non_const = cstr_non_const;
attrs = [];
} )
| {desc = Tconstr (p, _, _)} when Path.same p Predef.path_lazy_t ->
Copy link
Collaborator

@cristianoc cristianoc May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what would cause the recursive module test to fail.
I think that's fine, unless the recursive module example - with lazy - pattern is important to support.

@@ -34,10 +34,10 @@ type t<'a> = {

%%private(external fnToVal: (unit => 'a) => 'a = "%identity")
%%private(external valToFn: 'a => unit => 'a = "%identity")
%%private(external castToConcrete: lazy_t<'a> => t<'a> = "%identity")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can make lazy_t and t the same here, because lazy_t needs to be covariant and t is mutable. Also, the naming might change for clarity: currently lazy_t represents the type Lazy.t while t represents an internal implementation-only type used to generate specific js code (and cannot be exported as it would be unsound to export the mutable part anyway).

Copy link
Collaborator

@cristianoc cristianoc May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, bringing lazy_t out of builtins seems to bring clarity, as it makes a few things more explicit.

@cristianoc
Copy link
Collaborator

Here's a quick set of changes, minus cleanup:
master...quick_lazy

@cknitt cknitt requested a review from cristianoc May 18, 2025 10:15
@cknitt
Copy link
Member Author

cknitt commented May 18, 2025

@cristianoc Thanks a lot, PR updated.

Copy link

pkg-pr-new bot commented May 18, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7484

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7484

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7484

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7484

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7484

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7484

commit: 60228bf

@cknitt cknitt marked this pull request as ready for review May 18, 2025 10:21
@cknitt cknitt merged commit 59f4237 into master May 18, 2025
16 checks passed
@cknitt cknitt deleted the stdlib-lazy branch May 18, 2025 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants