What is #_currentArena? (Syntax) - flutter

I found this code in arena.dart in the ffi examples of flutter:
/// The last [Arena] in the zone.
factory Arena.current() {
return Zone.current[#_currentArena];
}
I am puzzled and could not find anything about the #_currentArena thing. What type of language construct is that, and how does it work? Trying to name anything (else) starting with # gives immediate errors; auto completion doesn't find it, and trying to go to its definition doesn't work either.
So this seems to be something extremely special, and extremely undocumented... leaving me extremely curious!
Link to source file in Flutter SDK Sqlite Example

As #pskink pointed out in his comment, this is part of the symbols.
A Symbol object represents an operator or identifier declared in a
Dart program. You might never need to use symbols, but they’re
invaluable for APIs that refer to identifiers by name, because
minification changes identifier names but not identifier symbols.
To get the symbol for an identifier, use a symbol literal, which is
just # followed by the identifier:
#radix
#bar
Symbol literals are compile-time constants.

Related

How to avoid not used function to be wiped out by optimizer

While compiling and Xcode swift project for MacOS, not used functions are removed from the binary (removed by the optimizer I guess). Is there a way to tell the compiler to not remove unused functions, perhaps with a compiler option (--force-attribute?) so that even with optimization enabled those functions remain in the binary?
I know that if a global function is declared as public (public func test()) then it's not removed even if not used (Since it can be used by other modules), but I can't use public since that would export the symbol for that function.
Any suggestion?
If this is indeed removed by the optimiser, then the answer is two-fold.
The optimiser removes only things that it can prove are safely removable. So to make it not remove something, you remove something that the optimiser uses to prove removability.
For example, you can change the visibility of a function in the .bc file by running a pass that makes the functions externally callable. When a function is private to the .bc file (also called module) and not used, then the compiler can prove that nothing will ever call it. If it's visible beyong the .bc file, then the compiler must assume that something can come along later and call it, so the function has to be left alive.
This is really the generic answer to how to prevent an optimisation: Prevent the compiler from inferring that the optimisation is safe.
Writing and invoking a suitable pass is left as an exercise for the reader. Writing should be perhaps 20 lines of code, invoking… might be simple, or not, it depends on your setting. Quite often you can add a call to opt to your build system.
As I discovered, the solution here is to use a magic compiler flag -enable-private-imports (described here: "...Allows this module's internal and private API to be accessed") which basically add the function name to the list #llvm.used that you can see in the bitcode, the purpose of the list is:
If a symbol appears in the #llvm.used list, then the compiler,
assembler, and linker are required to treat the symbol as if there is
a reference to the symbol that it cannot see (which is why they have
to be named)
(cit.) As described here.
This solves my original problem as the private function even if not used anywhere and not being public, during compilation is not stripped out by the optimiser.

Visual Studio Code Providers for language extension

I am trying to learn how to implement some of the helper providers: autocomplete, signature help and hover.
I am doing it for a framework that, as far as I know, it cannot be executed outside its main application, so one way I thought to go about this (get the objects types, methods and docs) is by parsing its documentation.
For example the Hover provider; once the cursor is hovering the word, I can search for it in the documentation and display the result:
class HSHoverProvider implements vscode.HoverProvider {
public provideSignatureHelp(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken
): vscode.SignatureHelp {
// get current word/line under the cursor and find a match inside the docs
...
return new vscode.Hover(data);
}
}
...
context.subscriptions.push(
vscode.languages.registerHoverProvider("lua", new HSHoverProvider())
);
This works fine when the action is directly on the initial declaration. I can parse directly the line and find what I need with a regex.
-- hovering over `application`, I check the context with a regex.
local app = hs.application('Code')
However, I am having a hard time when it comes to a "reference". Searching the document for the declaration of app with a regex approach leads to many edge cases, mainly because of the declaration scope:
Example:
-- declaration target
local app = hs.application('Code')
local function foo()
local app = hs.pasteboard()
end
local function bar()
if 'foo' then
local app = hs.alert()
end
do local app = hs.window.focusedWindow() end
-- a regex will have a hard time to understand which declaration is correct
print(app:title())
end
This lead me thinking that a regex is not the appropriate solution. I also thought that implementing vscode.DefinitionProvider will give me some insight but it did not.
I've tried to look at other extensions that do already the same thing (mainly Lua Language Server by sumneko), but I am not able to understand how they went for it (besides they are using the language server approach).
How would I go for something like this? Do I need an AST tree and inspect from there? Would using the language server be a better choice? Am I missing a bigger picture or I just need a more robust document parser?
Any insight is appreciated. Thanks in advance
The usual approach in such cases is to create a symbol table. You start by parsing the code for which you want to provide the tooling. From the parse tree (or syntax tree, depending on the parser tool used) you generate your symbol table, which holds the informations you need, including the nesting of blocks and symbols, the type of symbols (e.g. object name or object reference) and the scope for which a symbol is valid.

Using Conditional Syntax (Overrides) in BitBake

Reading a book on Yocto. Got to the following page, which says:
BitBake provides a very easy-to-use way to write conditional metadata.
It is done by a mechanism called overrides.
The OVERRIDES variable contains values separated by colons (:), and
each value is an item we want to satisfy conditions. So, if we have a
variable that is conditional on arm, and arm is in OVERRIDES, then the
version of the variable that is specific to arm is used rather than
the non-conditional version, as shown:
OVERRIDES = "architecture:os:machine"
TEST = "defaultvalue"
TEST_os = "osspecificvalue"
TEST_other = "othercondvalue"
In this example, TEST will be osspecificvalue due to the condition
of os being in OVERRIDES.
I'm unclear from this explanation how did TEST become equal to osspecificvalue. Would someone be able to explain it?
Bitbake implements it's own dictionary data structure based on Python's MutableMapping in lib/bb/data_smart.py. The goal is to create a dictionary with more flexibility in that each value in the "key,value" pair can be overridden based on specific identifiers.
If you look at how the variables in this dictionary are set, you will see that the datastore allows "overrides" of variables based on a list of override identifiers. These identifiers are expected to be appended with an underscore, like in your example of "TEST_os".
In the case you are referencing, "other" identifier is not in the list of OVERRIDES, so this "smart dictionary" does not override the value of TEST with "othercondvalue". However, because the "os" identifier is in the list of OVERRIDES, the value of TEST is indeed overridden with the value "osspecificvalue".
I would highly recommend reading through the DataSmart class as this is a very simplified explanation, but hopefully it helps.
Also, see the BitBake manual entry for OVERRIDES for more information.

Is it possible to reference a package from not within an import statement?

I'm writing a documentation about a Scala library. When I reference a certain package I do this with a String, e.g. "com.my.example" but would rather prefer to do this in a manner that gives me compile errors if anything breaks (e.g. (com.my.example).mkString).
Of course my IDE will warn me about such situations when refactoring and propose to fix those Strings for me. I'd just prefer to rely on the compiler instead of the IDE. Is this in some way possible? (Creating pseudo classes in each package to reference is not an option).
The compiler doesn't include comments, so it wouldn't break on that. You need to use scaladoc instead of scalac.
When you generate the documentation, you will see warnings for broken references.
For example I misspelled immutable intentionally and got this warning:
[warn] C:\...\Foo.scala:4: Could not find any member to link for "scala.collection.ommutable".
The key thing is to surround your references in double brackets [[ ]], eg:
/**
* This is my link [[scala.collection.ommutable]]
*/
For more info, check out http://docs.scala-lang.org/style/scaladoc.html

Package protected access modifyier with dot containing scope name

In Scala, there is a special type of access modifiers: protected[enclosing_scope]. But as soon as I try to use it with package names containing dots, like protected[framework.ui] i get "']' expected but '.' found" compiler error.
It seems really strange, since it is conventional to use dots in package/namespace names in java/.net. Do I miss something or is it impossible to use this access modifier with this type of scope names.
Update
I accepted an answer as it was relevant, though it seems impossible to make what I wanted
You can only restrict the visibility to a scope that you are in, so what do you need dots for?
If you are in
package foo.bar
you can make sth.
private[foo]
and
private[bar]
What is your use-case for the dots?