Remove static CodeContext access
The Problem
On concurrent compilation workloads where is possible to have multiple active CodeContext
with different configurations, current static implementation is not the best due to not always the current static CodeContext
is the currect at a given server running a compilation.
Concurrent compilation with multiple CodeConext
in use, is possible when we have a Language Server Protocol in use by two or more servers, one per project for code showing or editing in a multi-server environments like GNOME Builder or Microsoft Visual Studio Code.
Solution
Avoid to access static CodeContext
using CodeContext.get()
; but access to the current compilation by storing a reference in an object property or field requiring to access the current context.
Where static CodeContext is accessed from
Access to static CodeContext
is done in the following code:
$ grep -n "CodeContext\.get" vala/*.vala
vala/valaarraytype.vala:133: if (CodeContext.get ().profile == Profile.POSIX) {
vala/valaarraytype.vala:208: var context = CodeContext.get ();
vala/valaattribute.vala:51: if (!CodeContext.get ().deprecated) {
vala/valadatatype.vala:278: var context = CodeContext.get ();
vala/valadelegatedestroyfield.vala:33: base ("destroy", CodeContext.get ().analyzer.delegate_target_destroy_type, null, source_reference);
vala/valaenumvaluetype.vala:46: var string_type = new ObjectType ((Class) CodeContext.get ().root.scope.lookup ("string"));
vala/valaenumvaluetype.vala:51: if (CodeContext.get ().profile == Profile.POSIX) {
vala/valaerrortype.vala:47: base ((Symbol) error_domain ?? CodeContext.get ().root.scope.lookup ("GLib").scope.lookup ("Error"));
vala/valaerrortype.vala:102: var gerror_symbol = CodeContext.get ().root.scope.lookup ("GLib").scope.lookup ("Error");
vala/valagenericdestroyfield.vala:33: base ("destroy", CodeContext.get ().analyzer.delegate_target_destroy_type, null, source_reference);
vala/valagenericdupfield.vala:33: base ("dup", CodeContext.get ().analyzer.generics_dup_func_type, null, source_reference);
vala/valamethod.vala:1207: var bool_type = new BooleanType ((Struct) CodeContext.get ().root.scope.lookup ("bool"));
vala/valamethod.vala:1222: var glib_ns = CodeContext.get ().root.scope.lookup ("GLib");
vala/valamethod.vala:1260: var glib_ns = CodeContext.get ().root.scope.lookup ("GLib");
vala/valanulltype.vala:36: if (CodeContext.get ().experimental_non_null) {
vala/valaobjecttypesymbol.vala:343: if (CodeContext.get ().abi_stability) {
vala/valapointertype.vala:86: var context = CodeContext.get ();
vala/valareport.vala:377: CodeContext.get ().report.note (source, message);
vala/valareport.vala:380: CodeContext.get ().report.depr (source, message);
vala/valareport.vala:383: CodeContext.get ().report.depr (source, message);
vala/valareport.vala:386: CodeContext.get ().report.warn (source, message);
vala/valareport.vala:389: CodeContext.get ().report.err (source, message);
vala/valasignaltype.vala:76: var ulong_type = new IntegerType ((Struct) CodeContext.get ().root.scope.lookup ("ulong"));
vala/valasignaltype.vala:88: var ulong_type = new IntegerType ((Struct) CodeContext.get ().root.scope.lookup ("ulong"));
vala/valaversionattribute.vala:155: if (!CodeContext.get ().deprecated && (package_version == null || deprecated_since == null || VersionAttribute.cmp_versions (package_version, deprecated_since) >= 0)) {
vala/valaversionattribute.vala:165: if (CodeContext.get ().since_check && package_version != null && VersionAttribute.cmp_versions (package_version, since) < 0) {
vala/valaversionattribute.vala:175: if (!CodeContext.get ().experimental) {
Where to store a CodeContext reference
Checking out hierarchy, these are the base objects of classes where CodeContext
is used accessing the static one:
CodeNode->DataType->ReferenceType->Vala.ArrayType
CodeNode->Vala.Attribute
CodeNode->Vala.Datatype
CodeNode->Symbol->Variable->Field->Vala.DelegateDestroyField
CodeNode->DataType->ValueType->Vala.EnumValueType
CodeNode->DataType->ReferenceType->Vala.ErrorType
CodeNode->Symbol->Variable->Field->ValaGenericDestroyField
CodeNode->Symbol->Variable->Field->Vala.GenericDupField
CodeNode->Symbol->Subroutine->Vala.Method
CodeNode->DataType->ReferenceType->Vala.NullType
CodeNode->Symbol->TypeSymbol->ValaObjectTypeSymbol
CodeNode->DataType->rVala.PointerType
Vala.Report
CodeNode->DataType->CallableType->Vala.SignalType
Vala.VersionAttribute
After an inspection is possible to say that CodeNode
is the better candidate to attach the current CodeContext
, while Vala.Report
and Vala.VersionAttribute
are objects where is necessary to find a way to get current CodeContext
.
For Vala.Report
notice
, deprecated
, experimental
, warning
and record
we can access to a new added property for current CodeContext
and if null access to static one in order to avoid break software using this API.
For Vala.VersionAttribute
access to static CodeContext
is done at check()
, while all other has a CodeContext
parameter, this method doesn't, so add this attribute with a default value to NULL and make sure last version pass this value to Vala.VersionAttribute.check()
, while checks if a valid CodeContext
is passed, using a static one if not.