<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.pl-en
        {mso-style-name:pl-en;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Hi Craig,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Having a different signature in the table is an interesting idea, however it might lead to some trouble in lowering that expects to find the Fortran standard signatures (at least in terms of number of arguments
 and names).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">An alternative would be to allow partial characterization of absent arguments in evaluate::</span><span style="font-size:11.0pt">DummyDataObject. After all, it may not always be possible to come with a type
 and a shape for an absent argument. It is not very clear to me that setting an exact type and shape of absent arguments in the characteristics built for intrinsic procedures (</span><span style="font-size:9.0pt;font-family:Consolas;color:#24292E;background:white">evaluate::characteristics::Procedure</span><span style="font-size:11.0pt">)
  is useful. It might be worth checking if the information is actually needed in this case, and if not, to add a way to indicate that the exact characteristic of a DummyDataObject is unknown, and save the trouble of trying to build a type-spec for it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Jean</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt">From:</span></b><span style="font-size:11.0pt"> Rasmussen, Craig E. <rasmussen17@llnl.gov>
<br>
<b>Sent:</b> Monday, May 10, 2021 9:18 PM<br>
<b>To:</b> Jean Perier <jperier@nvidia.com><br>
<b>Cc:</b> flang-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [flang-dev] Intrinsic function with an optional TEAM_TYPE dummy argument<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<table class="MsoNormalTable" border="1" cellspacing="5" cellpadding="0" style="background:#FFEB9C">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><b><span style="font-size:7.5pt;font-family:"Verdana",sans-serif;color:black">External email: Use caution opening links or attachments</span></b><span style="font-size:7.5pt;font-family:"Verdana",sans-serif;color:black">
</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Hi Jean,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I’m actually happy to do this as long as it makes sense.  I’ve been really curious to know about how symbols and scopes work anyway.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">An alternative would be to have multiple entries in intrinsics.cpp for the optional team dummy arguments.  One entry for no team and one entry for a required team arg.  However, this is a bit of a hack.  I
 think I tried this out initially to see if it would work but I actually can’t remember if it fully does.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Whatever, let me know what you all think is the best way to proceed and I’ll muddle through.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Craig<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">From:
</span></b><span style="color:black">Jean Perier <<a href="mailto:jperier@nvidia.com">jperier@nvidia.com</a>><br>
<b>Date: </b>Friday, May 7, 2021 at 9:31 AM<br>
<b>To: </b>Rasmussen, Craig E. <<a href="mailto:rasmussen17@llnl.gov">rasmussen17@llnl.gov</a>><br>
<b>Cc: </b><a href="mailto:flang-dev@lists.llvm.org">flang-dev@lists.llvm.org</a> <<a href="mailto:flang-dev@lists.llvm.org">flang-dev@lists.llvm.org</a>><br>
<b>Subject: </b>RE: [flang-dev] Intrinsic function with an optional TEAM_TYPE dummy argument<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt">Hi Craig,</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Yes, the frontend should have seen iso_fortran_env if team_number is used, so you are right that it’s possible to get the type from that.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">The idea would be to go through the module scopes under the global scope (accessible via context.globalScope(), where context is the
</span><span class="pl-en"><span style="font-size:9.0pt;font-family:Consolas;color:black;background:white">SemanticsContext</span></span><span style="font-size:11.0pt">). Then you could look inside the builtin modules for a symbol named “__builtin_team_type”.
 With that type symbol, you should be able to create a semantics::</span><span class="pl-en"><span style="font-size:9.0pt;font-family:Consolas;color:black;background:white">DerivedTypeSpec</span></span><span style="font-size:11.0pt">, and then a semantics::DerivedTypeSpec
 (For the </span><span class="pl-en"><span style="font-size:9.0pt;font-family:Consolas;color:black;background:white">DerivedTypeSpec</span></span><span style="font-size:11.0pt">  sourceName, usually it would be the source position of the type-spec that relates
 to the object declaration, but here you can probably just use the one from the type symbol.)</span><span class="pl-en"><span style="font-size:9.0pt;font-family:Consolas;color:black;background:white">.</span></span><o:p></o:p></p>
<p class="MsoNormal"><span class="pl-en"><span style="font-size:9.0pt;font-family:Consolas;color:black;background:white"> </span></span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">You may want to make the return of this helper function optional and emit an error on the client side in case the modules were not loaded for some reasons, though I am not entirely sure if this can happen.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">You should be able to find how to do all that looking at semantics/scope.h, semantics/type.h and the implementation of semantics::IsBuiltinDerivedType (in semantics/tools.cpp). I think it can give you an interesting
 overview of how the front-end type system, symbols and scopes work, but if you do not want to deal with this part, let me know and I’ll give it a try.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Jean</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt">From:</span></b><span style="font-size:11.0pt"> flang-dev <<a href="mailto:flang-dev-bounces@lists.llvm.org">flang-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>Rasmussen, Craig E. via flang-dev<br>
<b>Sent:</b> Thursday, May 6, 2021 10:22 PM<br>
<b>To:</b> <a href="mailto:flang-dev@lists.llvm.org">flang-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [flang-dev] Intrinsic function with an optional TEAM_TYPE dummy argument</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"> <o:p></o:p></p>
<table class="MsoNormalTable" border="1" cellspacing="5" cellpadding="0" style="background:#FFEB9C">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><b><span style="font-size:7.5pt;font-family:"Verdana",sans-serif;color:black">External email: Use caution opening links or attachments</span></b><span style="font-size:7.5pt;font-family:"Verdana",sans-serif;color:black">
</span><o:p></o:p></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:11.0pt;color:white"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Hi Jean,</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Nope, what I tried didn’t work.  It looks like there is no current way to construct a characteristics::DummyArgument (of variant characteristics::DummyDataObject) without a TypeAndShape object and ultimately
 requiring a semantics::DerivedTypeSpec for the team type.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">As you said,</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">TEAM_TYPE, like all derived types defined by the standard, are defined by means of Fortran source files (see module/iso_fortran_env.f90 and module/__fortran_builtins.f90), so the compiler
 has no knowledge of what these derived types actually are without access to these source/module files (For user objects, these module files are made accessible by the user via use statements to iso_fortran_env).</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">The frontend will already have seen the iso_fortran_env source file so I’m wondering is special accessor functions could be provided with access to these types?</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">(Yikes, if TEAM_TYPE is this hard I’m really starting to worry about the array descriptor for coarrays.)</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Cheers,</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Craig</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">From:
</span></b><span style="color:black">Rasmussen, Craig E. <</span><a href="mailto:rasmussen17@llnl.gov">rasmussen17@llnl.gov</a><span style="color:black">><br>
<b>Date: </b>Thursday, May 6, 2021 at 11:42 AM<br>
<b>To: </b></span><a href="mailto:flang-dev@lists.llvm.org">flang-dev@lists.llvm.org</a><span style="color:black"> <</span><a href="mailto:flang-dev@lists.llvm.org">flang-dev@lists.llvm.org</a><span style="color:black">><br>
<b>Subject: </b>Re: [flang-dev] Intrinsic function with an optional TEAM_TYPE dummy argument</span><o:p></o:p></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt">Hi Jean,</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks for responding.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">You asked:</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">By “TypeAndShape constructor calls GetDefaultKind()”, you mean that GetDefaultKind is called in the arguments of a TypeAndShape constructor, not inside the TypeAndShape constructor
 function itself right?</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Correct, this is exactly what I was talking about though perhaps awkwardly worded.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Re.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">So going that way, I think you would need a semantics::DerivedTypeSpec for the team type. I am not sure there currently is a way to generate such DerivedTypeSpec without a user object
 (which I think would be your case, since there is no actual argument to get the type from).</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Yeah, I tried to go down this route and reached the same conclusion. If the optional argument is missing there won’t be an actual argument. Kind of painful.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">It just doesn’t feel to me like DynamicType is the right approach; we aren’t talking about polymorphic types in iso_fortran_env I don’t think.  I had wanted to do something like what happens when d.typePattern.kindCode
 == KindCode::same, however, as I recall, </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">     dummyArgs.emplace_back(dummyArgs[sameDummyArg.value()])</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">failed because of a problem with sameDummyArg.value().  If I understand the code correctly, nothing complicated is going on, we are just trying to put the same stupid dummy argument back on the list.  Hum,
 I just looked at this some more and I have some ideas I would like to try.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks again,</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Craig</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">From:
</span></b><span style="color:black">Jean Perier <</span><a href="mailto:jperier@nvidia.com">jperier@nvidia.com</a><span style="color:black">><br>
<b>Date: </b>Thursday, May 6, 2021 at 5:09 AM<br>
<b>To: </b>Rasmussen, Craig E. <</span><a href="mailto:rasmussen17@llnl.gov">rasmussen17@llnl.gov</a><span style="color:black">><br>
<b>Cc: </b></span><a href="mailto:flang-dev@lists.llvm.org">flang-dev@lists.llvm.org</a><span style="color:black"> <</span><a href="mailto:flang-dev@lists.llvm.org">flang-dev@lists.llvm.org</a><span style="color:black">><br>
<b>Subject: </b>RE: [flang-dev] Intrinsic function with an optional TEAM_TYPE dummy argument</span><o:p></o:p></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt">Hi Craig,</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I think you may be the first having to deal with optional derived type arguments in intrinsic functions. First, I would like to clarify where you are having an issue with IntrinsicTypeDefaultKinds::GetDefaultKind
 being called with a derived type category after your first three changes.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">By “TypeAndShape constructor calls GetDefaultKind()”, you mean that GetDefaultKind is called in the arguments of a TypeAndShape constructor, not inside the TypeAndShape constructor function itself right ?</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Is this at: </span><a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.us%2Fv3%2F__https%3A%2Fnam11.safelinks.protection.outlook.com%2F%3Furl%3Dhttps*3A*2F*2Furldefense.us*2Fv3*2F__https*3A*2Fgithub.com*2Fllvm*2Fllvm-project*2Fblob*2Fd8805574c183484f055552855fa82d2e8932415e*2Fflang*2Flib*2FEvaluate*2Fintrinsics.cpp*L1666__*3BIw!!G2kpM7uM-TzIFchu!hDkkoTDXWz2D4JfoCRcVEbwKxSmmoS0YhydSdaMxZC-GeYOgp-LFZ4r-5A_Kb59ZX9OV*24%26data%3D04*7C01*7Cjperier*40nvidia.com*7C4173d63013e549e1a74508d910d02033*7C43083d15727340c1b7db39efd9ccc17a*7C0*7C0*7C637559308353826720*7CUnknown*7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0*3D*7C1000%26sdata%3DmpnbJYG62UaErqN9yRE0oPJNi8KA3ugTK398ou9LtBY*3D%26reserved%3D0__%3BJSUlJSUlJSUlJSUlJSUlKiUlJSUlJSUlJSUlJSUlJQ!!G2kpM7uM-TzIFchu!h6zRU9VZyBMTknDtW-lI8JtNYpRyjsc1mpKGdOGnSxHSZhweetCxAEoW7B1OiS1Yc3nS%24&data=04%7C01%7Cjperier%40nvidia.com%7C208e3587f3ed40da528108d913e86496%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637562711118106098%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=g7TXiS3M36p05Gojizm3%2Bs0YNXHs%2BUp2xuTMBOgVOoU%3D&reserved=0"><span style="font-size:11.0pt">https://github.com/llvm/llvm-project/blob/d8805574c183484f055552855fa82d2e8932415e/flang/lib/Evaluate/intrinsics.cpp#L1666</span></a><span style="font-size:11.0pt">
 ?</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">} else {</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">      // optional argument is absent</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">      CHECK(d.optionality != Optionality::required);</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">      if (d.typePattern.kindCode == KindCode::same) {</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">        dummyArgs.emplace_back(dummyArgs[sameDummyArg.value()]);</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">      } else {</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">        auto category{d.typePattern.categorySet.LeastElement().value()};</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">        characteristics::TypeAndShape typeAndShape{</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">            DynamicType{category<b>, defaults.GetDefaultKind(category)}};</b></span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">        dummyArgs.emplace_back(std::string{d.keyword},</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt">            characteristics::DummyDataObject{std::move(typeAndShape)});</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Looking at the code you propose, the overall idea looks good to me, the issue is that DynamicType cannot be created from the simply the TypeCategory for derived type. A semantics::DerivedTypeSpec that precisely
 described the derived type specification of a derived type entity needs to be provided (DynamicType must be different for objects of different derived types, there cannot be a single DynamicType for all derived types).</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">So going that way, I think you would need a semantics::DerivedTypeSpec for the team type. I am not sure there currently is a way to generate such DerivedTypeSpec without a user object (which I think would
 be your case, since there is no actual argument to get the type from). That is because TEAM_TYPE, like all derived types defined by the standard, are defined by means of Fortran source files (see module/iso_fortran_env.f90 and module/__fortran_builtins.f90),
 so the compiler has no knowledge of what these derived types actually are without access to these source/module files (For user objects, these module files are made accessible by the user via use statements to iso_fortran_env).</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Jean</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt">From:</span></b><span style="font-size:11.0pt"> flang-dev <</span><a href="mailto:flang-dev-bounces@lists.llvm.org"><span style="font-size:11.0pt">flang-dev-bounces@lists.llvm.org</span></a><span style="font-size:11.0pt">>
<b>On Behalf Of </b>Rasmussen, Craig E. via flang-dev<br>
<b>Sent:</b> Monday, May 3, 2021 10:39 PM<br>
<b>To:</b> </span><a href="mailto:flang-dev@lists.llvm.org"><span style="font-size:11.0pt">flang-dev@lists.llvm.org</span></a><span style="font-size:11.0pt"><br>
<b>Subject:</b> [flang-dev] Intrinsic function with an optional TEAM_TYPE dummy argument</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"> <o:p></o:p></p>
<table class="MsoNormalTable" border="1" cellspacing="5" cellpadding="0" style="background:#FFEB9C">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><b><span style="font-size:7.5pt;font-family:"Verdana",sans-serif;color:black">External email: Use caution opening links or attachments</span></b><span style="font-size:7.5pt;font-family:"Verdana",sans-serif;color:black">
</span><o:p></o:p></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:11.0pt;color:white"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I'm trying to implement team_number(team) in lib/Evaluate/intrinsics.cpp and I'm running into a problem.  The issue is how to handle team_type from the intrinsic module iso_fortran_env.  I'll outline the steps
 I've taken so far and then describe the problem I'm having.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I’ve:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">  1. Changed the CategorySet in TypePattern TEAM_TYPE from IntType to DerivedType. I'm pretty sure this is the correct thing to do.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">  2. Added team_number to the IntrinsicInterface list with an optional TEAM_TYPE. Again, no problem here.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">  3. Implemented checking types and kinds of the actual argument against the team_number's interface. This is pretty straight forward:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">         case KindCode::teamType:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">           argOk = semantics::IsTeamType(GetDerivedTypeSpec(type));</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">The problem occurs when the code tries to check the dummy argument (team) for the case in which the optional actual argument is missing. The normal control flow path that this would take would be to move a
 characteristics::DummyDataObject (constructed with characteristics::TypeAndShape) onto the dummyArgs list. However, the TypeAndShape constructor calls GetDefaultKind() with a TEAM_TYPE category argument (which is TypeCategory::DerivedType).</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Therein lies the problem. The function IntrinsicTypeDefaultKinds::GetDefaultKind(TypeCategory::DerivedType) fails with a hard error because a derived type is not an intrinsic type. At first I was thoroughly
 confused by the whole type kind thing for a derived type, specifically one from an intrinsic module. Then as a last (of course) resort, I checked the standard more carefully and found Note 16.34 which states that types in intrinsic modules are not themselves
 intrinsic. Thus IntrinsicTypeDefaultKinds::GetDefaultKind(TypeCategory::DerivedType) should fail.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">So the conclusion is that I need help fixing this (for function team_type() and several other intrinsic functions with a dummy argument of TEAM_TYPE). The code could look something like the following (at roughly
 line 1670 in intrinsics.cpp):</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">      } else if (d.typePattern.kindCode == KindCode::teamType) {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        characteristics::TypeAndShape typeAndShape{DynamicType{TypeCategory::Derived}};</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        dummyArgs.emplace_back(std::string{d.keyword},</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">            characteristics::DummyDataObject{std::move(typeAndShape)});</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">      }</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">However, there is no constructor for TypeAndShape with a single argument of type TypeCategory::Derived. After staring at many lines of code in flang I'm left wondering if there shouldn't be?</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks,</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Craig</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
</div>
</div>
</body>
</html>