Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid breaking change on Libadalang.Auto_Provider.Get_Unit and Libadalang.Project_Provider.Get_Unit #970

Open
dsauvage opened this issue Jan 17, 2025 · 0 comments

Comments

@dsauvage
Copy link

Integrating libadalang 25.0.0 from libadalang 23.0.0

Calls to Libadalang.Auto_Provider.Get_Unit and Libadalang.Project_Provider.Get_Unit explicitly raise Program_Error exception.
Previously, developer was able to get a unit through the call

declare
  Unit : constant Libadalang.Analysis.Analysis_Unit'Class := LAL_Auto_Unit_Provider.Get_Unit
           (Context        => LAL_Context,
            Name           => Name,
            Kind           => Kind);

within the context below

declare
   LAL_Auto_Unit_Provider : Libadalang.Auto_Provider.Auto_Unit_Provider;
   LAL_Context            : Libadalang.Analysis.Analysis_Context;
begin
   LAL_Auto_Unit_Provider := Libadalang.Auto_Provider.Create_Auto_Provider (Input_Files => Files);
   Unit_Provider_Ref      := LAL_Auto_Unit_Provider.Create_Unit_Provider_Reference;
   LAL_Context            := Libadalang.Analysis.Create_Context (Unit_Provider => Unit_Provider_Ref);

This breaking change is related to the implementation of "PLE root" Langkit mechanism (Commit 1ab5c03 [1])

In order to maintain compatibility, Libadalang.Auto_Provider.Get_Unit and Libadalang.Project_Provider.Get_Unit could simply call the class underlying Get_Unit_And_PLE_Root, with the additional parameters Unit and PLE_Root_Index declared in the Get_Unit function scope, as proposed below instead of explicitly raising a Program_Error exception

 overriding function Get_Unit
   (Provider    : Auto_Unit_Provider;
    Context     : Analysis_Context'Class;
    Name        : Text_Type;
    Kind        : Analysis_Unit_Kind;
    Charset     : String := "";
    Reparse     : Boolean := False) return Analysis_Unit'Class
 is
    Unit           : Analysis_Unit := No_Analysis_Unit;
    PLE_Root_Index : Natural       := 0;
 begin
    Provider.Get_Unit_And_PLE_Root
      (Context        => Context,
       Name           => Name,
       Kind           => Kind,
       Charset        => Charset,
       Reparse        => Reparse,
       Unit           => Unit,
       PLE_Root_Index => PLE_Root_Index);
    return Unit;
 end Get_Unit;

[1]
1ab5c03#diff-405ad85e9a2303876561467d05a053fd2d5173d93fc6abd0bd55fd84d36d57c1

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

No branches or pull requests

1 participant