Skip to content

How do we restrict core libraries for macros? #1916

Open
@munificent

Description

@munificent

The macro proposal says:

Only the core libraries which don't violate the above rules are allowed... All other SDK libraries are not available.

What does this mean precisely? Some options:

  1. It is a compile-time error for the macro class created by a macro application to be declared in a library that contains an import of any prohibited library, imports any other library (transitively) that contains a prohibited import.

  2. It is a compile-time error for a macro class to refer to anything imported from a prohibited library. In other words, it's like the libraries exist but are completely empty.

  3. It is a macro execution-time error to call any function or method in a prohibited library. In other words, it's like the libraries exist but all function and method bodies are throw UnsupportedError().

I think we will also want to restrict some functionality in libraries that are otherwise allowed. For example, dart:core is allowed, but DateTime.now() should not be (#1915). Given that, option 3 might be the most consistent choice. In other words, all libraries are available but some functionality throws a runtime error. And it just happens to be that in some libraries like dart:isolate that all functions throw runtime errors.

I think there is prior art here for how things like dart:io are handled on Flutter that we can consult.

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions