Implement --noUnsafe compiler option #710
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an initial implementation of the general idea of an "unsafe" compiler option as described in #709, but a bit simpler.
--noUnsafe
Disallows the use of unsafe features in user code. Does not affect library files and external modules
This is fully backwards compatible in that the default is not changed, yet an embedder may now decide to disallow unsafe features in user code in order to protect from undefined behavior, like corruption of runtime structures by rogue stores and similar.
Instead of making stdlib files contagious as suggested in the original issue linked above, this PR refactors source kinds into
USER_ENTRY
normal entry file where exports become module exports
USER
normal file imported from user code
LIBRARY_ENTRY
library entry file where exports become globals
LIBRARY
normal library file
to keep all options open, e.g. if it ever becomes necessary to specify the file kind in asc. The runtime entry file is somewhat special in that it is both a library file and a user entry file (where exports become module exports), so it resorts to
USER_ENTRY
, since the RT entry doesn't use unsafe code anyway but just re-exports.