Skip to content

Comments

[DEMO for DIP1005] Converted imports to selective imports in std.array#4963

Merged
andralex merged 1 commit intodlang:masterfrom
andralex:selective_import_demo
Dec 17, 2016
Merged

[DEMO for DIP1005] Converted imports to selective imports in std.array#4963
andralex merged 1 commit intodlang:masterfrom
andralex:selective_import_demo

Conversation

@andralex
Copy link
Member

For the second demo I managed to replace all imports with selective imports in std.array. It was a major effort that involved grepping for heuristics such as "static if", "typeof", "^if", "compiles", "has", "\Wis" etc. A few examples of the difficulties for fun:

  1. Remove isStaticArray from the import list. The error is:
std/conv.d(4169): Error: static assert  "DirIteratorImpl cannot be emplaced from (string, SpanMode, bool)."
std/conv.d(4250):        instantiated from here: emplaceRef!(DirIteratorImpl, DirIteratorImpl, string, SpanMode, bool)
std/typecons.d(4998):        instantiated from here: emplace!(DirIteratorImpl, string, SpanMode, bool)
std/typecons.d(5091):        instantiated from here: initialize!(string, SpanMode, bool)
std/file.d(3802):        instantiated from here: __ctor!(string, SpanMode, bool)

This alone took me some 15-20 minutes and almost had me give up.

2, Remove hasElaborateAssign from the import list. The error is:

std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3812): Error: template instance std.conv.textImpl!(string, string, const(char)[]) error instantiating
std/format.d(912):        instantiated from here: text!(string, const(char)[])
std/bigint.d(867):        instantiated from here: FormatSpec!char
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(103): Error: template instance std.format.FormatSpec!(immutable(char)) error instantiating
std/conv.d(939):        instantiated from here: toStr!(string, dchar)
std/conv.d(172):        instantiated from here: toImpl!(string, dchar)
std/conv.d(3857):        instantiated from here: to!dchar
std/conv.d(3812):        ... (4 instantiations, -v to show) ...
std/format.d(977):        instantiated from here: parse!(int, const(char)[])
std/bigint.d(867):        instantiated from here: FormatSpec!char
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3812): Error: template instance std.conv.textImpl!(string, string, string, string) error instantiating
std/conv.d(58):        instantiated from here: text!(string, string, string)
std/conv.d(2072):        instantiated from here: convError!(const(char)[], int)
std/format.d(977):        instantiated from here: parse!(int, const(char)[])
std/bigint.d(867):        instantiated from here: FormatSpec!char
std/conv.d(2072): Error: template instance std.conv.convError!(const(char)[], uint) error instantiating
std/format.d(990):        instantiated from here: parse!(uint, const(char)[])
std/bigint.d(867):        instantiated from here: FormatSpec!char
std/format.d(1011): Error: template instance std.conv.parse!(ubyte, const(char)[]) error instantiating
  1. Remove isAssignable. Error message is:
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3812): Error: template instance std.conv.textImpl!(string, string, const(char)[]) error instantiating
std/format.d(912):        instantiated from here: text!(string, const(char)[])
std/bigint.d(867):        instantiated from here: FormatSpec!char
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(103): Error: template instance std.format.FormatSpec!(immutable(char)) error instantiating
std/conv.d(939):        instantiated from here: toStr!(string, dchar)
std/conv.d(172):        instantiated from here: toImpl!(string, dchar)
std/conv.d(3857):        instantiated from here: to!dchar
std/conv.d(3812):        ... (4 instantiations, -v to show) ...
std/format.d(977):        instantiated from here: parse!(int, const(char)[])
std/bigint.d(867):        instantiated from here: FormatSpec!char
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3857): Error: template std.array.Appender!string.Appender.put cannot deduce function from argument types !()(string), candidates are:
std/array.d(2823):        std.array.Appender!string.Appender.put(U)(U item) if (canPutItem!U)
std/array.d(2851):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutConstRange!Range)
std/array.d(2860):        std.array.Appender!string.Appender.put(Range)(Range items) if (canPutRange!Range)
std/conv.d(3812): Error: template instance std.conv.textImpl!(string, string, string, string) error instantiating
std/conv.d(58):        instantiated from here: text!(string, string, string)
std/conv.d(2072):        instantiated from here: convError!(const(char)[], int)
std/format.d(977):        instantiated from here: parse!(int, const(char)[])
std/bigint.d(867):        instantiated from here: FormatSpec!char
std/conv.d(2072): Error: template instance std.conv.convError!(const(char)[], uint) error instantiating
std/format.d(990):        instantiated from here: parse!(uint, const(char)[])
std/bigint.d(867):        instantiated from here: FormatSpec!char
std/format.d(1011): Error: template instance std.conv.parse!(ubyte, const(char)[]) error instantiating
  1. Remove isImplicitlyConvertible with the result:
std/range/primitives.d(347): Error: static assert  "Cannot put a const(char) into a Appender!string."
std/format.d(1452):        instantiated from here: put!(Appender!string, const(char))
std/format.d(3485):        instantiated from here: formatValue!(Appender!string, ulong, char)
std/format.d(464):        instantiated from here: formatGeneric!(Appender!string, ulong, char)
std/format.d(6482):        ... (1 instantiations, -v to show) ...
std/typecons.d(400):        instantiated from here: format!(char, ulong, ulong)
std/encoding.d(3468):        instantiated from here: Tuple!(BOM, "schema", ubyte[], "sequence")

@timotheecour
Copy link
Contributor

couldn't that be done with tooling ? (if not with existing traits, at least via instrumenting dmd)

Copy link
Member

@WalterBright WalterBright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@WalterBright
Copy link
Member

Why not pull it?

@andralex andralex changed the title [DEMO][DONOTPULL] Converted imports to selective imports in std.array [DEMO] Converted imports to selective imports in std.array Dec 17, 2016
@andralex
Copy link
Member Author

@timotheecour it could, but @WalterBright warned the tool would be highly nontrivial.

@WalterBright good idea, I'll pull.

@andralex andralex changed the title [DEMO] Converted imports to selective imports in std.array [DEMO for DIP1005] Converted imports to selective imports in std.array Dec 17, 2016
@andralex andralex force-pushed the selective_import_demo branch from f69b6eb to e064d56 Compare December 17, 2016 16:50
@andralex
Copy link
Member Author

Auto-merge toggled on

@andralex andralex merged commit 9965433 into dlang:master Dec 17, 2016
@CyberShadow
Copy link
Member

@timotheecour it could, but @WalterBright warned the tool would be highly nontrivial.

Just brute-force it.

Expand all imports to selective imports of all symbols, then wrap imports in a DustMite comment block and run it through DustMite. We did something similar at DConf 2016 to minimize imports in ddmd.

@CyberShadow
Copy link
Member

Which Phobos modules do you want this done on? I could do this in bulk. (After my current reduction finishes.)

@andralex
Copy link
Member Author

@CyberShadow the point of this experiment is to illustrates the steps (and the ongoing maintenance) needed to take advantage of lazy imports, which have not been implemented. As of now, doing this is just giving us more maintenance to do of these lists.

@CyberShadow
Copy link
Member

Sorry, I don't get it? Was this PR made to prove some point?

It was a major effort

Well... all I'm saying is that it didn't need to be.

Is there any practical reason why I shouldn't have a go at replacing module imports with selective imports throughout Phobos? Really shouldn't take much effort, just some setup and CPU time to do the reduction.

I'm confused, if this change was not good, then why was it merged? And if it was good, then why shouldn't we have more of it, especially if there's an easy way to do it?

@andralex
Copy link
Member Author

Sorry, I don't get it? Was this PR made to prove some point?

Yes. The point was to preview the kind of setup that would have all explicit declarations.

It was a major effort

Well... all I'm saying is that it didn't need to be.

Understood, thanks.

Is there any practical reason why I shouldn't have a go at replacing module imports with selective imports throughout Phobos?

The replacement has no value except it adds one extra chore to maintain.

I'm confused, if this change was not good, then why was it merged? And if it was good, then why shouldn't we have more of it, especially if there's an easy way to do it?

I will undo the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants