Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:31
    runfoapp[bot] edited #58202
  • 19:31
    runfoapp[bot] edited #52658
  • 19:31
    runfoapp[bot] edited #58199
  • 19:31
    runfoapp[bot] edited #58197
  • 19:31
    runfoapp[bot] edited #58077
  • 19:31
    runfoapp[bot] edited #57982
  • 19:31
    runfoapp[bot] edited #57980
  • 19:31
    runfoapp[bot] edited #57797
  • 19:31
    runfoapp[bot] edited #57722
  • 19:31
    runfoapp[bot] edited #57423
  • 19:31
    runfoapp[bot] edited #57565
  • 19:31
    runfoapp[bot] edited #57551
  • 19:31
    runfoapp[bot] edited #56625
  • 19:31
    runfoapp[bot] edited #55638
  • 19:30
    runfoapp[bot] edited #49400
  • 19:30
    runfoapp[bot] edited #48816
  • 19:30
    runfoapp[bot] edited #49026
  • 19:30
    runfoapp[bot] edited #46414
  • 19:30
    runfoapp[bot] edited #53392
  • 19:30
    runfoapp[bot] edited #53391
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...
Andrew Hill
@AartBluestoke
should i cross-post to dotnet/coreclr then?
Antony Male
@canton7
Yeah, but as the loop grows to something realistic, those movs will become less significant
arturohernandez10
@arturohernandez10
Does anyone know if of any work on limited scope partial application on C#? Something as simple as tagging an array known at compile time for expansion during compilation as well.
CyrusNajmabadi
@CyrusNajmabadi
sorry, not sure what you're asking about
Something as simple as tagging an array known at compile time for expansion during compilation as well.
can you expand (no pun intended) on what you're asking about?
arturohernandez10
@arturohernandez10

@CyrusNajmabadi
Sure...

        public static void Original()
    {
        var attributes = new [] { new { Name = "Country", Include = false }};
        var dict = new Dictionary<string,string>(){{"Country", "USA"}};
        var list = new List<string>();

        foreach (var attribute in attributes)
            if (attribute.Include)
                list.Add(dict[attribute.Name]);                
    }

    public static void Expanded()
    {
        var dict = new Dictionary<string,string>(){{"Country", "USA"}};
        var list = new List<string>();

        list.Add(dict["USA"]);                
    }
}

It's a somewhat contrived example. In general, you have a variable like attributes in this case, whose entire contents are known at compile time. Expanding only within a limited scope, may be a tractable problem. I clearly used foreach rather than whereas part of limiting the scope. Many coding patterns could be expressed in a similar way, while keeping a good amount of type and syntax checking. And of course this would be useful in code generation.

CyrusNajmabadi
@CyrusNajmabadi
sure. you could use source-generators to solve the above.
look for whatever pattern you want, and generate the final form as-app
arturohernandez10
@arturohernandez10
@CyrusNajmabadi Do you know of any previous, useful or similar work. I'd rather not reinvent the wheel.
CyrusNajmabadi
@CyrusNajmabadi
not really...
there are likely lots of source generators you could look at
but your use case is pretty specific
but would be very feasible with the source generator (and other) roslyn apis.