Skip to content

Index data incomplete when relying on protocol conformance in another module #64612

@keith

Description

@keith

With this code:

// Module0
public struct Foo {
    public init() {}
}

public protocol Bar {}
// Module1
import Module0

extension Foo: Bar {}
// Module2
import Module0

public func baz(_: Bar) {}
// Module3
import Module0
import Module1
import Module2

func qux() {
    baz(Foo())
}

The index data for Module3 does not contain any references to Module1, even though the conformance defined in Module1 is required for the code to compile. This is easiest to visualize with indexutil-annotate:

// Module3
/*
       module=Module0=usr is c:@M@Module0
       v  */
import Module0
/*
       module=Module1=usr is c:@M@Module1
       v  */
import Module1
/*
       module=Module2=usr is c:@M@Module2
       v  */
import Module2

/*
     function=qux()=usr is s:7Module33quxyyF
     v  */
func qux() {
    /*
    function=baz(_:)=usr is s:7Module23bazyy7Module03Bar_pF
    |   struct=Foo=usr is s:7Module03FooV
    |   constructor=init()=usr is s:7Module03FooVACycfc
    v   v  */
    baz(Foo())
}

Steps to reproduce

Using this project: protocolext.zip and indexutil-annotate:

  1. swift build
  2. indexutil-annotate .build/debug/index/store/ Sources/Module3/Module3.swift

You can also inspect the record naively with strings to see there are no other string references to Module1:

% strings $(find .build/debug/index/store/v5/records -name "Module3.swift*")
IDXR
Module0c:@M@Module0
Module1c:@M@Module1
Module2c:@M@Module2
qux()s:7Module33quxyyF
baz(_:)s:7Module23bazyy7Module03Bar_pF
Foos:7Module03FooV
init()s:7Module03FooVACycfc

Expected behavior

I think ideally there would be something in the index data showing that Module1 is depended on by this unit. I'm not sure exactly what it would point to.

Environment

  • Swift compiler version info 5.7.2
  • Xcode version info 14.2.14C18

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.conformancesFeature → protocol: protocol conformancesexpressionsFeature: expressionsindexingArea → source tooling: AST indexingmultiple modulesFlag: An issue whose reproduction requires multiple modulesprotocolFeature → type declarations: Protocol declarationssource toolingArea: IDE support, SourceKit, and other source toolingswift 5.7unexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions