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

Adjust specification regarding dynamic exceptions which happen when accessing deferred library which is not loaded #3481

Closed
mraleph opened this issue Nov 24, 2023 · 4 comments
Labels
question Further information is requested specification

Comments

@mraleph
Copy link
Member

mraleph commented Nov 24, 2023

Section 19.1.2 Semantics of Imports says the following about top-level functions

  For every top level function $f$ named \id{} in
  \NamespaceName{\metavar{import},i},
  a corresponding function named \id{} with the same signature as $f$.
  % This error can occur because being-loaded is a dynamic property.
  Calling the function results in a dynamic error,
  and so does closurizing it
  (\ref{functionClosurization}).

This seems to imply that checking whether library is loaded or not happens on invocation and we have test language/deferred/not_loaded_check_test which tries to test that during evaluation of an expression lib.f(sideEffect()) where lib is not loaded the following will happen:

  1. sideEffect is executed
  2. An Error is thrown.

However CFE implements a different semantics (ever since it started to support deferred loading, see CL): checking whether the library is loaded or not is done before arguments are evaluated.

I suggest we update specification to match the implementation. Test update CL: https://dart-review.googlesource.com/c/sdk/+/338125

Related issue dart-lang/sdk#54151

@mraleph mraleph added the bug There is a mistake in the language specification or in an active document label Nov 24, 2023
@mraleph
Copy link
Member Author

mraleph commented Nov 24, 2023

cc @eernstg

@eernstg eernstg added question Further information is requested specification and removed bug There is a mistake in the language specification or in an active document labels Nov 24, 2023
@eernstg
Copy link
Member

eernstg commented Nov 24, 2023

Presumably, we can specify the semantics where the dynamic error occurs before any actual arguments are evaluated, because (IIUC) the CFE determines the behavior of all backends in this case. So we don't even have to consider making it an implementation specific behavior, or in any way allowing for both orderings.

See #3483.

@lrhn
Copy link
Member

lrhn commented Nov 24, 2023

Agree, the attempted access to any name through the deferred prefix should throw, as if prefix.name... was guarded by !prefix._loaded ? throw ...an error... : prefix.name....

(And I remembered the previous behavior before we fixed it to what it is today. Which was worse.)

copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Nov 28, 2023
Change this test to match the current CFE implementation
which has been in place for 5 years (e2ad2db)

We should probably update specification instead of changing
CFE: dart-lang/language#3481

[email protected]

Change-Id: Iccbecfa8c29733b3e163d2b13d4df79e277999fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338125
Reviewed-by: Erik Ernst <[email protected]>
Commit-Queue: Slava Egorov <[email protected]>
@eernstg
Copy link
Member

eernstg commented Nov 28, 2023

I'm closing this, given that the language specification has been updated to match the implemented semantics. @mraleph, please reopen if you think there is more to do.

@eernstg eernstg closed this as completed Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested specification
Projects
None yet
Development

No branches or pull requests

3 participants