Comments (4)
@lrhn we seem to have some ambiguity between the way String.fromEnvironment is documented and implemented.
The documentation seems to indicate that the constructor is only guaranteed to work when invoked as const and may work on some platforms that have access to compiler options. However the non const invocations of it seems to work in an AOT environment too, The following program:
void main() {
print('Foo: ${String.fromEnvironment('foo')}');
print('Bar: ${const String.fromEnvironment('bar')}');
}
dart run -Dfoo='foo' -Dbar='bar' test.dart results in:
Foo: foo
Bar: bar
If we compile this to an AOT snapshot with no defines provided (dart compile aot-snapshot test.dart
) and invoke dartaotruntime
with the same defines as the JIT run (dartaotruntime -Dfoo='foo' -Dbar='bar' test.aot)
, we see the following:
Foo: foo
Bar:
Is the documentation correct or the implementation in the VM.
The reason this comes up here is because this issue has been filed to implement support for environment variables in spawnUri and if String.fromEnviroment
is supposed to work only for the const constructor than this support becomes meaningless for the AOT case and it should probably also not do it in the JIT case in order to keep the behavior consistent between AOT and JIT.
from sdk.
Seems like the VM implementation used whatever is available at the time of execution of the constructor.
The const invocation uses what was provided when the AoT program was compiled, the ringtone uses what was provided to it for the non-const invocation.
If we consider non-const invocation as unspecified behavior, then it cannot be wrong.
I'd still suggest to make the dartaotruntime
ignore any -D
flags, and treat the compilation environment as empty at runtime. That way nobody can start depending on it.
(I'd even make JIT code treat non-const invocations as running on an empty environment for consistency, but it's less important since it'll show as a single consistent environment. The example here could probably show different values for the same key, depending on whether it's const or not.)
from sdk.
About spawnUri
, I don't really understand how it works if not JIT-compiled. If it can target an AoT compiled program too, then I also wouldn't let that program see any compilation environment values.
For JIT spawnUri
, compiler options could make sense, but I'd also be perfectly happy just using the same options as the running isolate. The use-case for changing compiler flags for an isolate seems likely to be testing, and JIT-only. Maybe it could be an option in dart:developer
, so it's not used in production.
from sdk.
Is there any reason we wouldn't want to support runtime environment variables and just document the behavior? If this only worked for one of the runtimes, I'd agree it's worth making the behavior consistent. However, both native runtime modes support this behavior in what I'd consider an unsurprising way (the const
constructor results in a compile time constant and the non-const
constructor performs a lookup at runtime). Given the implementation can be done completely within the VM without explicit configuration by the embedder, I think it's safe to document this behavior as a feature.
If we're dead set against doing this, there really should be a way to prevent the non-const constructors from being invoked, either through a compile time error or throwing an exception.
from sdk.
Related Issues (20)
- analysis_options.yaml "include:" not working for nested folders unless workspace root has a package config for the referenced package HOT 15
- Some javascript error are caught with an opaque JavascriptError type when using wasm HOT 3
- Network paths don't work after 3.4.0 HOT 4
- Intersection type soundness issue HOT 1
- language/nnbd/late/covariant_instance_field_test fails with inlining disabled HOT 4
- `Uint8List.fromList([...])` is ~10x slower than `Uint8List(length)..[0] = #..[1] = #` HOT 2
- [native_assets] Spaces in paths HOT 2
- Unreliable network connection timeout parameters HOT 4
- A simple code that break dart fix HOT 3
- Code completion doesn't suggest enum values when imported aliased HOT 1
- Allow DTD clients to know when a service/method is available/unavailable HOT 6
- [ffi] Varargs should give an error on uint8, int8, uint16, int16 and float HOT 2
- Failures on Expose CommentToken as analyzer public API...[analyzer] Prioritize errors in analysis_options/pubspec errors when running "dart analyze" HOT 1
- ffi/callback_unwind_error_test was flaky, turned Crash on vm-aot-linux-release-arm-qemu
- Failures on Expose CommentToken as analyzer public API...[analyzer] HOT 3
- [dart2js] dart2js should do better inlining of `@Native` method stubs
- Docs on how to access and use the test status database HOT 4
- Isolate-local native callables create spurious exception in debugger when returning null HOT 3
- [breaking change] Change the context for the operand of `throw` to `Object`. HOT 1
- Create a method to know if a type is a Built-in type HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.