Skip to content

funcsem.d: use selective import for tip - #23727

Closed
WalterBright wants to merge 1 commit into
dlang:masterfrom
WalterBright:funcsem.d
Closed

funcsem.d: use selective import for tip#23727
WalterBright wants to merge 1 commit into
dlang:masterfrom
WalterBright:funcsem.d

Conversation

@WalterBright

Copy link
Copy Markdown
Member

Trying to minimize the use of errors.d

@WalterBright

Copy link
Copy Markdown
Member Author

Why is public tip not seen in errors.d? It compiles fine on my machine.

@0xEAB

0xEAB commented Aug 27, 2026

Copy link
Copy Markdown
Member

Fails on my machine:

$ make -j16
Using D host compiler: ldmd2
ldmd2 -ofgenerated/build -g compiler/src/build.d
generated/build dmd
(TX) VERSION
(TX) SYSCONFDIR
(TX) DMD_CONF
(DC) COMMON
(DC) LEXER
(DC) BACKEND

The following operation failed:
Name: lexer
Dependencies: 
 -> /home/mindy/dev/dmd/generated/linux/release/64/VERSION
 -> common

Sources: 
 -> /home/mindy/dev/dmd/compiler/src/dmd/console.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/entity.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/errors.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/errorsink.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/file_manager.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/globals.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/id.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/identifier.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/lexer.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/location.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/tokens.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/array.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/bitarray.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/ctfloat.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/file.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/filename.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/hash.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/port.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/region.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/rmem.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/stringtable.d
 -> /home/mindy/dev/dmd/compiler/src/dmd/root/utf.d

Targets: 
 -> /home/mindy/dev/dmd/generated/linux/release/64/lexer.o

Command: /usr/local/bin/ldmd2 -c -of/home/mindy/dev/dmd/generated/linux/release/64/lexer.o -vtls -J/home/mindy/dev/dmd/compiler/src/dmd/res -w -de -fPIC -J/home/mindy/dev/dmd/generated/linux/release/64 -I/home/mindy/dev/dmd/compiler/src -g -m64 -color=on src/dmd/console.d src/dmd/entity.d src/dmd/errors.d src/dmd/errorsink.d src/dmd/file_manager.d src/dmd/globals.d src/dmd/id.d src/dmd/identifier.d src/dmd/lexer.d src/dmd/location.d src/dmd/tokens.d src/dmd/root/array.d src/dmd/root/bitarray.d src/dmd/root/ctfloat.d src/dmd/root/file.d src/dmd/root/filename.d src/dmd/root/hash.d src/dmd/root/port.d src/dmd/root/region.d src/dmd/root/rmem.d src/dmd/root/stringtable.d src/dmd/root/utf.d

-----------------------------------------------------------
/home/mindy/dev/dmd/compiler/src/dmd/funcsem.d(35): Error: module `dmd.errors` import `tip` not found
import dmd.errors : tip;
       ^

Update

static import + alias fails in a similar fashion

src/dmd/funcsem.d(71): Error: undefined identifier `tip` in module `dmd.errors`
private alias tip = dmd.errors.tip;

@0xEAB

0xEAB commented Aug 27, 2026

Copy link
Copy Markdown
Member

My monkey patch also fails.

--- a/compiler/src/dmd/errors.d
+++ b/compiler/src/dmd/errors.d
@@ -580,7 +580,7 @@ __gshared DiagnosticHandler diagnosticHandler;
  *      ...    = printf-style variadic arguments
  */
 static if (__VERSION__ < 2092)
-    public extern (C++) void tip(const(char)* format, ...)
+    public extern (C++) void _tip(const(char)* format, ...)
     {
         va_list ap;
         va_start(ap, format);
@@ -588,7 +588,7 @@ static if (__VERSION__ < 2092)
         va_end(ap);
     }
 else
-    public pragma(printf) extern (C++) void tip(const(char)* format, ...)
+    public pragma(printf) extern (C++) void _tip(const(char)* format, ...)
     {
         va_list ap;
         va_start(ap, format);
@@ -597,6 +597,8 @@ else
     }
 
 
+alias tip = _tip;
+
 // Encapsulates a diagnostic as described by its location, format message, and kind.
/home/mindy/dev/dmd/compiler/src/dmd/errors.d(600): Error: undefined identifier `_tip`, did you mean alias `tip`?
alias tip = _tip;

@Herringway

Copy link
Copy Markdown
Contributor

The problem appears to be #19204.

@0xEAB

0xEAB commented Aug 27, 2026

Copy link
Copy Markdown
Member

Workaround

--- a/compiler/src/dmd/errors.d
+++ b/compiler/src/dmd/errors.d
@@ -573,13 +573,16 @@ alias DiagnosticHandler = bool delegate(const ref SourceLoc location, Color head
  */
 __gshared DiagnosticHandler diagnosticHandler;
 
+static if (__VERSION__ < 2092)
+    version = preD2092;
+
 /**
  * Print a tip message with the prefix and highlighting.
  * Params:
  *      format = printf-style format specification
  *      ...    = printf-style variadic arguments
  */
-static if (__VERSION__ < 2092)
+version (preD2092)
     public extern (C++) void tip(const(char)* format, ...)
     {
         va_list ap;

@WalterBright

Copy link
Copy Markdown
Member Author

@Herringway yes, I think you nailed it.

@0xEAB

0xEAB commented Aug 27, 2026

Copy link
Copy Markdown
Member
src/dmd/errors.d(577): Error: version `preD2092` defined after use
src/dmd/errors.d(594): Error: unrecognized `pragma(printf)`

Looks like the bootstrapping compiler has a few more issues.

@WalterBright

Copy link
Copy Markdown
Member Author

@0xEAB yes, I just ran into the same problem.

@0xEAB

0xEAB commented Aug 27, 2026

Copy link
Copy Markdown
Member

@WalterBright
To my defense: With a more recent compiler used for bootstrapping, my workaround would function.

@WalterBright

Copy link
Copy Markdown
Member Author

Why to we have a tip function anyway? How is that different from message?

@WalterBright

Copy link
Copy Markdown
Member Author

There are only two uses of it, and both look replaceable by errorSupplemental.

@0xEAB

0xEAB commented Aug 27, 2026

Copy link
Copy Markdown
Member

Yeah, we could probably remove tip().

But: AFAICT we’ll run into the same issue with the static import and static if that guards those other diagnostic functions.

@WalterBright

Copy link
Copy Markdown
Member Author

Those other diagnostic functions are no longer being called. At least when my PRs are pulled! They can be dumped.

@WalterBright

Copy link
Copy Markdown
Member Author

tip() no longer needed

@WalterBright
WalterBright deleted the funcsem.d branch August 28, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants