Share resolved companion contexts by tier
This commit is contained in:
@@ -218,6 +218,8 @@ declarations, and existing diagnostic sites.
|
|||||||
|
|
||||||
## Finding 7 — Each derived companion keeps a copy of the same tier context
|
## Finding 7 — Each derived companion keeps a copy of the same tier context
|
||||||
|
|
||||||
|
**Status** — Complete. Each tier creates at most one shared derived context and has no per-input context table. The development check and full race suite passed.
|
||||||
|
|
||||||
**Priority P3.** `acquireUnderlayGroupScopes` allocates a context pointer
|
**Priority P3.** `acquireUnderlayGroupScopes` allocates a context pointer
|
||||||
slot for every input, even in tiers with no bindings. Each derived input
|
slot for every input, even in tiers with no bindings. Each derived input
|
||||||
then gets an addressable copy of the same main context with the same
|
then gets an addressable copy of the same main context with the same
|
||||||
|
|||||||
@@ -38,31 +38,30 @@ func acquireImportedInput(request importAcquisitionRequest, policy *acquisitionP
|
|||||||
source := request.input.input.source
|
source := request.input.input.source
|
||||||
context := request.input.input.filesystem
|
context := request.input.input.filesystem
|
||||||
main := request.main
|
main := request.main
|
||||||
resolved, diagnostic := resolvedFilesystemContext{}, (*Diagnostic)(nil)
|
resolved := request.input.resolved
|
||||||
if request.input.resolved != nil {
|
if resolved == nil {
|
||||||
resolved = *request.input.resolved
|
value, diagnostic := resolveFilesystemContext(source, context, main, tier.hostToken)
|
||||||
} else {
|
if diagnostic != nil {
|
||||||
resolved, diagnostic = resolveFilesystemContext(source, context, main, tier.hostToken)
|
return nil, sourceInfos(main.source), nil, []Diagnostic{*diagnostic}
|
||||||
}
|
}
|
||||||
if diagnostic != nil {
|
resolved = &value
|
||||||
return nil, sourceInfos(main.source), nil, []Diagnostic{*diagnostic}
|
|
||||||
}
|
}
|
||||||
if resolved.native == nil {
|
if resolved.native == nil {
|
||||||
if diagnostic := validateResolvedFilesystemDirectories(resolved); diagnostic != nil {
|
if diagnostic := validateResolvedFilesystemDirectories(*resolved); diagnostic != nil {
|
||||||
return nil, sourceInfos(main.source), nil, []Diagnostic{*diagnostic}
|
return nil, sourceInfos(main.source), nil, []Diagnostic{*diagnostic}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
access, err := openResolvedFilesystemAccess(resolved)
|
access, err := openResolvedFilesystemAccess(*resolved)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
diagnostic := globFilesystemDiagnostic(err, "configuration root could not be opened", Location{})
|
diagnostic := globFilesystemDiagnostic(err, "configuration root could not be opened", Location{})
|
||||||
diagnostic.Primary = nil
|
diagnostic.Primary = nil
|
||||||
return nil, sourceInfos(main.source), nil, []Diagnostic{diagnostic}
|
return nil, sourceInfos(main.source), nil, []Diagnostic{diagnostic}
|
||||||
}
|
}
|
||||||
composition, sources, diagnostics := acquireImportedWithAccess(request, policy, state, tier, access, resolved)
|
composition, sources, diagnostics := acquireImportedWithAccess(request, policy, state, tier, access, *resolved)
|
||||||
if len(diagnostics) != 0 {
|
if len(diagnostics) != 0 {
|
||||||
return composition, sources, nil, diagnostics
|
return composition, sources, nil, diagnostics
|
||||||
}
|
}
|
||||||
return composition, sources, &resolved, nil
|
return composition, sources, resolved, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func acquireImportedWithAccess(request importAcquisitionRequest, policy *acquisitionPolicy, loadState *acquisitionState, tier *tierAcquisitionState, access *filesystemAccess, resolved resolvedFilesystemContext) (*composedDocument, []SourceInfo, []Diagnostic) {
|
func acquireImportedWithAccess(request importAcquisitionRequest, policy *acquisitionPolicy, loadState *acquisitionState, tier *tierAcquisitionState, access *filesystemAccess, resolved resolvedFilesystemContext) (*composedDocument, []SourceInfo, []Diagnostic) {
|
||||||
|
|||||||
@@ -276,23 +276,27 @@ func applyCompletedTier(
|
|||||||
func acquireUnderlayGroupScopes(group loadGroup, index int, rule *VersionRule, state *acquisitionState, policy acquisitionPolicy, mainContext *resolvedFilesystemContext) (*acquiredUnderlayGroup, []Diagnostic) {
|
func acquireUnderlayGroupScopes(group loadGroup, index int, rule *VersionRule, state *acquisitionState, policy acquisitionPolicy, mainContext *resolvedFilesystemContext) (*acquiredUnderlayGroup, []Diagnostic) {
|
||||||
initialBytes, initialNodes := state.accounting.bytes, state.accounting.nodes
|
initialBytes, initialNodes := state.accounting.bytes, state.accounting.nodes
|
||||||
tier := &tierAcquisitionState{visited: make(map[resourceIdentity]importRoute), hostToken: &namespaceToken{}}
|
tier := &tierAcquisitionState{visited: make(map[resourceIdentity]importRoute), hostToken: &namespaceToken{}}
|
||||||
selected := make([]*resolvedFilesystemContext, len(group.inputs))
|
var derived *resolvedFilesystemContext
|
||||||
for i, contribution := range group.inputs {
|
bind := func(input loadInput) (loadInput, *resolvedFilesystemContext) {
|
||||||
if contribution.filesystem == nil && contribution.mainRelative != nil && mainContext != nil {
|
if input.filesystem != nil || input.mainRelative == nil {
|
||||||
derived := *mainContext
|
return input, nil
|
||||||
derived.mainPath = ""
|
|
||||||
derived.hostToken = tier.hostToken
|
|
||||||
selected[i] = &derived
|
|
||||||
} else if contribution.filesystem == nil && contribution.mainRelative != nil {
|
|
||||||
group.inputs[i].filesystem = contribution.mainRelative.Fallback
|
|
||||||
}
|
}
|
||||||
|
if mainContext == nil {
|
||||||
|
input.filesystem = input.mainRelative.Fallback
|
||||||
|
return input, nil
|
||||||
|
}
|
||||||
|
if derived == nil {
|
||||||
|
context := *mainContext
|
||||||
|
context.mainPath = ""
|
||||||
|
context.hostToken = tier.hostToken
|
||||||
|
derived = &context
|
||||||
|
}
|
||||||
|
return input, derived
|
||||||
}
|
}
|
||||||
nativeAnchors := make(map[*namespaceToken]string)
|
nativeAnchors := make(map[*namespaceToken]string)
|
||||||
for inputIndex, contribution := range group.inputs {
|
for inputIndex, contribution := range group.inputs {
|
||||||
token := nativeTokenForLoadInput(contribution)
|
contribution, resolved := bind(contribution)
|
||||||
if selected[inputIndex] != nil && selected[inputIndex].native != nil {
|
token := nativeTokenForLoadInput(contribution, resolved)
|
||||||
token = selected[inputIndex].native.token
|
|
||||||
}
|
|
||||||
if token != nil {
|
if token != nil {
|
||||||
if _, exists := nativeAnchors[token]; !exists {
|
if _, exists := nativeAnchors[token]; !exists {
|
||||||
nativeAnchors[token] = explicitNamespaceAnchor(index, inputIndex+1)
|
nativeAnchors[token] = explicitNamespaceAnchor(index, inputIndex+1)
|
||||||
@@ -302,10 +306,11 @@ func acquireUnderlayGroupScopes(group loadGroup, index int, rule *VersionRule, s
|
|||||||
acquiredGroup := &acquiredUnderlayGroup{index: index}
|
acquiredGroup := &acquiredUnderlayGroup{index: index}
|
||||||
inclusionGraph := newImportInclusionGraph()
|
inclusionGraph := newImportInclusionGraph()
|
||||||
for inputIndex, contribution := range group.inputs {
|
for inputIndex, contribution := range group.inputs {
|
||||||
|
contribution, resolved := bind(contribution)
|
||||||
acquired, diagnostics := acquireInput(inputAcquisitionRequest{
|
acquired, diagnostics := acquireInput(inputAcquisitionRequest{
|
||||||
input: contribution, role: sourceVersionContribution,
|
input: contribution, role: sourceVersionContribution,
|
||||||
resolved: selected[inputIndex],
|
resolved: resolved,
|
||||||
withoutBase: contribution.mainRelative != nil && contribution.filesystem == nil && selected[inputIndex] == nil,
|
withoutBase: contribution.mainRelative != nil && contribution.filesystem == nil && resolved == nil,
|
||||||
directiveContext: rootDirectiveContextLayered, protectionRule: rule,
|
directiveContext: rootDirectiveContextLayered, protectionRule: rule,
|
||||||
}, policy, state, tier)
|
}, policy, state, tier)
|
||||||
for _, source := range acquired.sources {
|
for _, source := range acquired.sources {
|
||||||
@@ -324,10 +329,7 @@ func acquireUnderlayGroupScopes(group loadGroup, index int, rule *VersionRule, s
|
|||||||
kind: "host", host: explicitNamespaceAnchor(index, 0),
|
kind: "host", host: explicitNamespaceAnchor(index, 0),
|
||||||
input: explicitNamespaceAnchor(index, inputIndex+1),
|
input: explicitNamespaceAnchor(index, inputIndex+1),
|
||||||
}
|
}
|
||||||
token := nativeTokenForLoadInput(contribution)
|
token := nativeTokenForLoadInput(contribution, resolved)
|
||||||
if selected[inputIndex] != nil && selected[inputIndex].native != nil {
|
|
||||||
token = selected[inputIndex].native.token
|
|
||||||
}
|
|
||||||
if token != nil {
|
if token != nil {
|
||||||
anchors.kind = "native"
|
anchors.kind = "native"
|
||||||
anchors.native = nativeAnchors[token]
|
anchors.native = nativeAnchors[token]
|
||||||
@@ -411,7 +413,10 @@ func composeUnderlayGroup(acquired *acquiredUnderlayGroup, rule *VersionRule, po
|
|||||||
return composition, nil
|
return composition, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func nativeTokenForLoadInput(input loadInput) *namespaceToken {
|
func nativeTokenForLoadInput(input loadInput, resolved *resolvedFilesystemContext) *namespaceToken {
|
||||||
|
if resolved != nil && resolved.native != nil {
|
||||||
|
return resolved.native.token
|
||||||
|
}
|
||||||
if input.source.kind == sourceFilesystem && input.source.namespace != nil {
|
if input.source.kind == sourceFilesystem && input.source.namespace != nil {
|
||||||
return input.source.namespace.token
|
return input.source.namespace.token
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user