Share resolved companion contexts by tier
This commit is contained in:
@@ -276,23 +276,27 @@ func applyCompletedTier(
|
||||
func acquireUnderlayGroupScopes(group loadGroup, index int, rule *VersionRule, state *acquisitionState, policy acquisitionPolicy, mainContext *resolvedFilesystemContext) (*acquiredUnderlayGroup, []Diagnostic) {
|
||||
initialBytes, initialNodes := state.accounting.bytes, state.accounting.nodes
|
||||
tier := &tierAcquisitionState{visited: make(map[resourceIdentity]importRoute), hostToken: &namespaceToken{}}
|
||||
selected := make([]*resolvedFilesystemContext, len(group.inputs))
|
||||
for i, contribution := range group.inputs {
|
||||
if contribution.filesystem == nil && contribution.mainRelative != nil && mainContext != nil {
|
||||
derived := *mainContext
|
||||
derived.mainPath = ""
|
||||
derived.hostToken = tier.hostToken
|
||||
selected[i] = &derived
|
||||
} else if contribution.filesystem == nil && contribution.mainRelative != nil {
|
||||
group.inputs[i].filesystem = contribution.mainRelative.Fallback
|
||||
var derived *resolvedFilesystemContext
|
||||
bind := func(input loadInput) (loadInput, *resolvedFilesystemContext) {
|
||||
if input.filesystem != nil || input.mainRelative == nil {
|
||||
return input, nil
|
||||
}
|
||||
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)
|
||||
for inputIndex, contribution := range group.inputs {
|
||||
token := nativeTokenForLoadInput(contribution)
|
||||
if selected[inputIndex] != nil && selected[inputIndex].native != nil {
|
||||
token = selected[inputIndex].native.token
|
||||
}
|
||||
contribution, resolved := bind(contribution)
|
||||
token := nativeTokenForLoadInput(contribution, resolved)
|
||||
if token != nil {
|
||||
if _, exists := nativeAnchors[token]; !exists {
|
||||
nativeAnchors[token] = explicitNamespaceAnchor(index, inputIndex+1)
|
||||
@@ -302,10 +306,11 @@ func acquireUnderlayGroupScopes(group loadGroup, index int, rule *VersionRule, s
|
||||
acquiredGroup := &acquiredUnderlayGroup{index: index}
|
||||
inclusionGraph := newImportInclusionGraph()
|
||||
for inputIndex, contribution := range group.inputs {
|
||||
contribution, resolved := bind(contribution)
|
||||
acquired, diagnostics := acquireInput(inputAcquisitionRequest{
|
||||
input: contribution, role: sourceVersionContribution,
|
||||
resolved: selected[inputIndex],
|
||||
withoutBase: contribution.mainRelative != nil && contribution.filesystem == nil && selected[inputIndex] == nil,
|
||||
resolved: resolved,
|
||||
withoutBase: contribution.mainRelative != nil && contribution.filesystem == nil && resolved == nil,
|
||||
directiveContext: rootDirectiveContextLayered, protectionRule: rule,
|
||||
}, policy, state, tier)
|
||||
for _, source := range acquired.sources {
|
||||
@@ -324,10 +329,7 @@ func acquireUnderlayGroupScopes(group loadGroup, index int, rule *VersionRule, s
|
||||
kind: "host", host: explicitNamespaceAnchor(index, 0),
|
||||
input: explicitNamespaceAnchor(index, inputIndex+1),
|
||||
}
|
||||
token := nativeTokenForLoadInput(contribution)
|
||||
if selected[inputIndex] != nil && selected[inputIndex].native != nil {
|
||||
token = selected[inputIndex].native.token
|
||||
}
|
||||
token := nativeTokenForLoadInput(contribution, resolved)
|
||||
if token != nil {
|
||||
anchors.kind = "native"
|
||||
anchors.native = nativeAnchors[token]
|
||||
@@ -411,7 +413,10 @@ func composeUnderlayGroup(acquired *acquiredUnderlayGroup, rule *VersionRule, po
|
||||
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 {
|
||||
return input.source.namespace.token
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user