i’ve got a truly overgrown piece of MongoDB SQL that looks like:
$0[.pipeline] = .init
{
$0.stage
{
$0[.match] = .init
{
$0[.expr] = .expr
{
$0[.and] = .init
{
$0.expr
{
$0[.eq] = ("$\(Record[.scope])", id)
}
$0.expr
{
$0[.or] = .init
{
$0.expr
{
$0[.and] = .init
{
$0.expr
{
...
this thing takes about 25s to typecheck, a number i got by timing the build with and without the query body.
when i make a tiny addition:
$0[.pipeline] = .init
{
$0.stage
{
$0[.match] = Mongo.PredicateDocument.init
+++ ^~~~~~~~~~~~~~~~~~~~~~~
{
it takes about 3s to typecheck.
i have seen this problem before with generic and heavily overloaded subscripts, but in this case, the subscript called in $0[.match] is a plain old non-generic subscript with no overloads.
extension Mongo.PipelineStage
{
@inlinable public
subscript(key:Match) -> Mongo.PredicateDocument?
{
get
{
nil
}
set(value)
{
self.bson.push(key, value)
}
}
}
why doesn’t it just “know” that the .init(with:) should be a Mongo.PredicateDocument.init(with:)?