[VM/runtime] - detect null safety before isolate initialization

- Detect null safety when not specified before isolate
      initialization
      - for source files by having CFE parse the source file
        for @dart annotations
      - for kernel files by sniffing the kernel file for
        compilation mode
      - for appJIT files by sniffing the feature string
      - for AOT snapshots by sniffing the feature string

    - Remove workaround of returning null safety to false during
      bootstrapping

    - Add a new Dart C API call for detecting null safety

Bug: 41766
Change-Id: Ia8cf264323a2d0d58c2855ce6491456aa6f1da07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150089
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
asiva
2020-06-11 01:22:35 +00:00
committed by commit-bot@chromium.org
parent c0c66ab10f
commit a782dd82db
33 changed files with 886 additions and 337 deletions
+45 -1
View File
@@ -532,6 +532,7 @@ typedef struct {
Dart_QualifiedFunctionName* entry_points;
bool load_vmservice_library;
bool copy_parent_code;
bool null_safety;
} Dart_IsolateFlags;
/**
@@ -3313,8 +3314,8 @@ typedef enum {
typedef struct {
Dart_KernelCompilationStatus status;
bool null_safety;
char* error;
uint8_t* kernel;
intptr_t kernel_size;
} Dart_KernelCompilationResult;
@@ -3370,6 +3371,49 @@ DART_EXPORT void Dart_SetDartLibrarySourcesKernel(
const uint8_t* platform_kernel,
const intptr_t platform_kernel_size);
/**
* Detect the null safety opt-in status.
*
* When running from source, it is based on the opt-in status of `script_uri`.
* When running from a kernel buffer, it is based on the mode used when
* generating `kernel_buffer`.
* When running from an appJIT or AOT snapshot, it is based on the mode used
* when generating `snapshot_data`.
*
* \param script_uri Uri of the script that contains the source code
*
* \param package_config Uri of the package configuration file (either in format
* of .packages or .dart_tool/package_config.json) for the null safety
* detection to resolve package imports against. If this parameter is not
* passed the package resolution of the parent isolate should be used.
*
* \param original_working_directory current working directory when the VM
* process was launched, this is used to correctly resolve the path specified
* for package_config.
*
* \param snapshot_data
*
* \param snapshot_instructions Buffers containing a snapshot of the
* isolate or NULL if no snapshot is provided. If provided, the buffers must
* remain valid until the isolate shuts down.
*
* \param kernel_buffer
*
* \param kernel_buffer_size A buffer which contains a kernel/DIL program. Must
* remain valid until isolate shutdown.
*
* \return Returns true if the null safety is opted in by the input being
* run `script_uri`, `snapshot_data` or `kernel_buffer`.
*
*/
DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri,
const char* package_config,
const char* original_working_directory,
const uint8_t* snapshot_data,
const uint8_t* snapshot_instructions,
const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size);
#define DART_KERNEL_ISOLATE_NAME "kernel-service"
/*