Skip to content
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

chore: backend tweaks #4890

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

chore: backend tweaks #4890

wants to merge 5 commits into from

Conversation

ggreif
Copy link
Contributor

@ggreif ggreif commented Feb 5, 2025

Broken out of #4608. Mostly harmless cleanups.

@ggreif ggreif requested a review from a team as a code owner February 5, 2025 15:40
@@ -2540,7 +2540,7 @@ module Closure = struct
I32Type :: Lib.List.make n_args I32Type,
FakeMultiVal.ty (Lib.List.make n_res I32Type))) in
(* get the table index *)
Tagged.load_forwarding_pointer env ^^
(*Tagged.load_forwarding_pointer env ^^ FIXME: NOT needed, accessing immut slots*)
Copy link
Contributor

Choose a reason for hiding this comment

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

Did @luc-blaeser approve this? Seems a bit risky to me.

Copy link
Contributor

@crusso crusso Feb 5, 2025

Choose a reason for hiding this comment

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

Hmm, maybe that's ok because its only accessing the fun ptr field of the closure which is just an immutable field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how Luc wants to implement named (shared) functions, maybe then the index changes? Better ask!

Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that targets of immutable slots can also be moved by GC, so this extra step is necessary I believe

@@ -2540,7 +2540,7 @@ module Closure = struct
I32Type :: Lib.List.make n_args I32Type,
FakeMultiVal.ty (Lib.List.make n_res I32Type))) in
(* get the table index *)
Tagged.load_forwarding_pointer env ^^
(*Tagged.load_forwarding_pointer env ^^ FIXME: NOT needed, accessing immut slots*)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there can never be a mutation of the funptr_field between old space and newspace. Maybe we should have Tagged.load_immutable_field (= Tagged.load_field) to signify that load_forwarding_pointer is not needed.

@@ -5520,7 +5520,7 @@ module IC = struct
| Flags.(ICMode | RefMode) ->
system_call env "call_cycles_add128"
| _ ->
E.trap_with env "cannot accept cycles when running locally"
E.trap_with env "cannot add cycles when running locally"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy&paste error

@@ -10937,9 +10936,8 @@ and compile_prim_invocation (env : E.t) ae p es at =

StackRep.of_arity return_arity,
code1 ^^ StackRep.adjust env fun_sr SR.Vanilla ^^
Closure.prepare_closure_call env ^^ (* FIXME: move to front elsewhere too *)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some fields (that could have mutable portions) could be in newspace, so let's do this eagerly. TODO: spot other similar uses...

N.B. Line 10943 potentially looked into oldspace, but probably only loaded an immutable field (function index?).

@@ -10937,9 +10936,8 @@ and compile_prim_invocation (env : E.t) ae p es at =

StackRep.of_arity return_arity,
code1 ^^ StackRep.adjust env fun_sr SR.Vanilla ^^
Closure.prepare_closure_call env ^^ (* FIXME: move to front elsewhere too *)
Copy link
Contributor

Choose a reason for hiding this comment

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

So this now storing the prepared (forwarded closure in clos and re_loading it later to pass to call_closure (already forwarded). I guess that's ok. @luc-blaeser ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this won't save an instruction, but following the recent pointer in both cases sounds like a good idea (less cache misses :-)

@ggreif ggreif marked this pull request as draft February 5, 2025 16:40
Copy link

github-actions bot commented Feb 5, 2025

Comparing from b0123f5 to a83ae09:
The produced WebAssembly code seems to be completely unchanged.

@@ -2332,7 +2330,7 @@ module Closure = struct
I64Type :: Lib.List.make n_args I64Type,
FakeMultiVal.ty (Lib.List.make n_res I64Type))) in
(* get the table index *)
Tagged.load_forwarding_pointer env ^^
(*Tagged.load_forwarding_pointer env ^^ FIXME: NOT needed, accessing immut slots*)
Copy link
Contributor

Choose a reason for hiding this comment

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

Targets of immutable slots may also be moved by the GC.

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.

3 participants