Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:21
    CyrusNajmabadi closed #43112
  • 00:21
    CyrusNajmabadi commented #43112
  • 00:20
    CyrusNajmabadi commented #50570
  • 00:16
    CyrusNajmabadi commented #59023
  • 00:15
    CyrusNajmabadi labeled #59023
  • 00:15
    CyrusNajmabadi unlabeled #59023
  • 00:15
    CyrusNajmabadi commented #59023
  • Jan 23 20:48
    CyrusNajmabadi edited #42873
  • Jan 23 20:47
    CyrusNajmabadi edited #42864
  • Jan 23 20:45
    CyrusNajmabadi synchronize #59034
  • Jan 23 20:39
    CyrusNajmabadi synchronize #59034
  • Jan 23 20:38
    CyrusNajmabadi synchronize #42873
  • Jan 23 20:29
    Youssef1313 synchronize #59031
  • Jan 23 20:14
    CyrusNajmabadi synchronize #42873
  • Jan 23 20:04
    CyrusNajmabadi synchronize #42864
  • Jan 23 19:52
    CyrusNajmabadi synchronize #42864
  • Jan 23 19:38
    CyrusNajmabadi synchronize #42864
  • Jan 23 19:37
    CyrusNajmabadi edited #42864
  • Jan 23 19:36
    CyrusNajmabadi edited #42864
  • Jan 23 19:35
    CyrusNajmabadi commented #42864
Bernd Baumanns
@bernd5
global usings are only visible in script code
But how can we load a new net6.0 project with implicit usings?
Should we generate a CompilationUnit with those global usings?
Egil Hansen
@egilhansen:matrix.org
[m]

Hey people, just a sanity check before I waste more time... can I have a source generator create a class with a partial unimplemented method, and then have the user implement that method in a class they write manually?

Generation works, and the compiler complains afterword's that CS8795 Partial method 'MyClass.MyMethod(CancellationToken)' must have an implementation part because it has accessibility modifiers.

But when I in the user project create a class in the right namespace with the right name, the CS8795 error goes away but is replaced with a CS0759 No defining declaration found for implementing declaration of partial method 'MyClass.MeMethod(CancellationToken)'.

So that leads me to think that this approach is not possible?

Yair Halberstadt
@YairHalberstadt
It should work fine. Is that a VS error, or a compilation error?
I.e. does it work fine when you compile it.
Egil Hansen
@egilhansen:matrix.org
[m]
@YairHalberstadt it seems like a build time error
I am using c#10 and a rc1 nightly though
Egil Hansen
@egilhansen:matrix.org
[m]
Arrrg nevermind. Guess it was a chicken and eg thing. I had three partial method generated, and once I implemented all three all the errors went away.
well sort of, Visual Studio is still not happy and continue to report CS0759
Yair Halberstadt
@YairHalberstadt
Yeah visual studio tooling still isn't perfect with SGs.
You can report that as a roslyn bug and hopefully it'll get fixed some time.
egilhansen
@egilhansen:matrix.org
[m]
Yep, its the same with the blazor soruce generator. in gneral SGs are cool, but e.g. having the ability to delete generated files that are no longer relevant, e.g. because the user renamed or moved a file, is pretty high on the list of things to have.
Yair Halberstadt
@YairHalberstadt
I don't understand what that means? SGs generate a fresh set of files every compilation. You should never need to delete any.
egilhansen
@egilhansen:matrix.org
[m]
So e.g. i changed my analyzer to produce file1 instead of file_1, and the later was not removed, and was still picked up by the compiler.
If you rename a Blazor (.razor) file you sometimes have to restart vs to get things working again.
Yair Halberstadt
@YairHalberstadt
That sounds like a VS problem, not a roslyn problem. Should work fine from the compiler
Egil Hansen
@egilhansen:matrix.org
[m]
You might be right
Adam Speight
@AdamSpeight2008
Could Source Generators be used to generate the various Syntax Nodes and BoundNodes used by the compilers themself?
Eg Boot Strap build then nodes and then compile the rest of the selection.
CyrusNajmabadi
@CyrusNajmabadi
Source generators do that :)
That is how we generate the syntax nodes.
See CSharpSyntaxGenerator.
Adam Speight
@AdamSpeight2008
I meant using the language feature "Source Generators" to generate them, rather the "manually pre-source generators" way of generating source code.
CyrusNajmabadi
@CyrusNajmabadi
yes. that's what i'm saying
CSharpSyntaxGenerator uses the language feature 'Source Generators'
and
Bernd Baumanns
@bernd5
Project.GetSourceGeneratedDocumentsAsync seems to query / build the Compilation
(Project based on MSBuildWorkspace)
This is okay - but it takes quite a long time even if the project has no source generator
Is there some way to determine if a project has source generators?
Oh, new projects seem to have an implicit SourceGenerator
Bernd Baumanns
@bernd5
"System.Text.Json.SourceGeneration.JsonSourceGenerator"
Bernd Baumanns
@bernd5
Can we disable it?
I mean I don't want a JsonSourceGenerator for projects which do nothing with Json...
Where is it defined?
Bernd Baumanns
@bernd5
Is it intended or a bug?
CyrusNajmabadi
@CyrusNajmabadi
it's intentional if the project links in (Somehow) that generator.
it's possible it's built into the sdk.
you might need to create a discussion on the sdk side of things asking if there's a way to disable this.
Bernd Baumanns
@bernd5
@CyrusNajmabadi thanks
Do you know where I can create such a discussion? Which repo?
CyrusNajmabadi
@CyrusNajmabadi
Andrew Hill
@AartBluestoke

https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIGYACMhgYQYG8aHunGBLAHYYGAFSgBPABQBKDlx4LBw3AFd8AXgAMAbnkLuGCZ2r7TDAGbQGkpQz5btdgDzlNOuwGoP0vWdOr8D3U+XRMzAF8GMGwMMAALdnDfBWSeYgB2BgDQhSTqGl96OyEGADkIMSlZYz9bAIdU00soa1t7dz4XN0c+Lx8wv381IJDGpkzs3zyacKA=

    public int Try() {
        int sum=0;
        try{
            for (int i=0; i<100; i++)
                sum+=i;
        } catch{}

        return sum;
    }


    public int NoTry() {
        int sum=0;
            for (int i=0; i<100; i++)
                sum+=i;
        return sum;
    }

adding a try{...}catch{} around a trivial for loop can strongly affect its optimisation ; is this expected?

Antony Male
@canton7
The actual loop hasn't changed that much -- it's got a couple more movs
Andrew Hill
@AartBluestoke
those movs make it about 3x as slow when you benchmark.net it (but i don't know of an online code fragment benchmark)
Bernd Baumanns
@bernd5
Yeah, the data is now stored on the stack instead of register usage
This would be more a runtime question - roslyn compiles only to IL...